$(function() {

	var width = $(window).width()-230;
	$("#main-iframe").attr("style", "margin-left: 230px; position: absolute; width:" + width + "px; height:100%;");

	//Sidebar Accordion Menu:
	$("#main-nav li ul").hide(); // Hide all sub menus
	$("#main-nav li a.current").parent().find("ul").slideToggle("slow"); // Slide down the current menu item's sub menu
	
	$("#main-nav li a.nav-top-item").click(function () {
			$(this).parent().siblings().find("ul").slideUp("normal"); // Slide up all sub menus except the one clicked
			$(this).next().slideToggle("normal"); // Slide down the clicked sub menu
			return false;
		}
	);
	
	$("#main-nav a").click(function() {
		var $this = $(this);
		if ($this.hasClass("nav-top-item") && !$this.hasClass("no-submenu")) return false;
		$("#main-nav a").removeClass("current");
		if (!($this.hasClass("nav-top-item"))) {
			$this.parent().parent().prev().addClass("current");
		}
		$this.addClass("current");
		var href = $this.attr("href");
		if (href != "") {
			$("#main-iframe").attr("src", href);
		}
		return false;
	});

	// Sidebar Accordion Menu Hover Effect:
	$("#main-nav li .nav-top-item").hover(
		function () {
			$(this).stop().animate({ paddingRight: "25px" }, 200);
		}, 
		function () {
			$(this).stop().animate({ paddingRight: "15px" });
		}
	);

});

function onClose() {
	$.ajax({
		url: 'close',
		type: 'post',
		async: false
	});
}
